package main

//type Client struct {
//	ID     string
//	Mutx   sync.Mutex
//	Socket *websocket.Conn
//	Send   chan SendMsg
//	Rev    chan []byte
//}

type client struct {
	ID    string
	Brand string
	Type  string
	Sdt   chan []byte
	Rdt   chan []byte
	Client
}

//var clientMap map[string]client

type Client interface {
	Send(message []byte) error
	Read() ([]byte, error)
	//websocket获取id
	GetID() string
	GetRdt() chan []byte
	GetSdt() chan []byte
	Start()
}

func NewClient(config Config) Client {
	switch config.Type {
	case "websocket":
		return &WebsocketClient{
			ID:   config.ID,
			Sdt:  make(chan []byte),
			Rdt:  make(chan []byte),
			Err:  make(chan error),
			Conn: config.WebsocketConn,
		}
	}
	return nil
}

func (c *client) Send(message []byte) error {
	c.Sdt <- message
	return nil
}

func (c *client) Read() ([]byte, error) {
	var readBuff []byte
	readBuff = <-c.Rdt
	return readBuff, nil
}

func (c *client) Start() {
	switch c.Brand {
	case NVFBrand:
		go c.Start()
	}
}

func (c *client) GetID() string {
	return c.ID
}
